<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>用户管理</title>
	<meta name="decorator" content="default"/>
	<style type="text/css">
		.BoxDiv{
			position:fixed;
			padding-left:30px;
			padding-top:20px;
			width:400px;
			height:200px;
			background:#f5f5f5;
			top:10%;
			left:25%;
			margin:0 auto;
			border:1px solid #CCC;
			box-shadow:3px 3px 10px 4px #DDD;
		}
		.BoxDiv .ib_title{
			margin-bottom:35px;
		}
	</style>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#changeMoneyForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				rules:{
					sum:{
						required:true,number:true,min:0.01,minNumber:true}
				},
				messages:{
					sum:{
						required:"请输入调整额度",
						number:"请输入正确金额",
						min: "输入最小金额为0.01"
					}
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element.next());
					}
				}
			});
			jQuery.validator.addMethod("minNumber",function(value, element){
				var returnVal = true;
				inputZ=value;
				var ArrMen= inputZ.split(".");    //截取字符串
				if(ArrMen.length==2){
					if(ArrMen[1].length>2){    //判断小数点后面的字符串长度
	                    returnVal = false;
	                    return false;
	                }
	            }
	            return returnVal;
			},"小数点后最多为两位"); 
		});
		//额度调整
		function changeMoneyDivOpen(){
			var creditMoney = $("#creditMoney").val();
			$("#nowCredit").text((creditMoney==null||creditMoney=='')?0:creditMoney);
			$("#changeMoneyDiv").show();
		}
		function changeMoneyDivClose(){
			$("#changeMoneyDiv").hide();
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/sys/commonUser/vipUserInfoList">会员信息设置</a></li>
		<li class="active"><a href="${ctx}/sys/commonUser/creditLine?id=${user.id}">信用额度设置</a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="credit" action="${ctx}/sys/yonguser/user/save" method="post" class="form-horizontal">
		<div style="display:none">
			<sys:message content="${message}"/>	
		</div>
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<input id="creditMoney" value="${credit.money }" type="hidden"/>
		<div class="control-group">
			<label class="control-label">信用额度：</label>
			<div class="controls">
				<label class="lbl">￥${credit.money==null?0:(credit.money)} 元</label>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">剩余可用额度：</label>
			<div class="controls">
				<label class="lbl">￥${credit.money==null?0:(credit.money+credit.rechargeMoney-credit.useMoney)} 元</label>
			</div>
		</div>
		<div class="control-group">
		<div class="controls" style="margin-left:47px">
			<a class="btn btn-primary" onclick="changeMoneyDivOpen()">额度调整</a>
			<c:if test="${credit.status!=0 }">
				<a class="btn btn-primary" href="${ctx}/sys/commonUser/freezeCredit?id=${user.id}" onclick="return confirmx('确定冻结该会员信用额度？', this.href)">冻结</a>
			</c:if>
			<c:if test="${credit.status==0 }">
				<a class="btn btn-primary" href="${ctx}/sys/commonUser/unfreezeCredit?id=${user.id}" onclick="return confirmx('确定解冻该会员信用额度？', this.href)">解冻</a>
			</c:if>
			<a class="btn btn-primary" href="${ctx}/sys/commonUser/transactionHistoryShow?userId=${user.id}">交易记录调整</a>
		</div>
		</div>
		<label style="font-weight: bold;">额度历史记录</label>
			<table id="contentTable" class="table table-striped table-bordered table-condensed">
			<thead>
				<tr>
					<th>信用额度</th>
					<th>可用额度</th>
					<th>类型</th>
					<th>金额</th>
					<th>操作日期</th>
				</tr>
			</thead>
			<tbody>
			<c:if test="${empty page.list}">
				<tr>
				<td colspan="5">暂无记录</td>
				</tr>
			</c:if>
			<c:if test="${not empty page.list}">
			<c:forEach items="${page.list}" var="userEditHistroy">
				<tr>
					<td>￥${userEditHistroy.money}</td>
					<td>￥${userEditHistroy.remainMoney }</td>
					<td>${fns:getDictLabel(userEditHistroy.moneyType, 'money_type', '')}</td>
					<c:if test="${userEditHistroy.sum==null }">
						<td>--</td>
					</c:if>
					<c:if test="${userEditHistroy.sum!=null }">
						<td>￥${userEditHistroy.sum }</td>
					</c:if>
					<td><fmt:formatDate value="${userEditHistroy.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
				</tr>
			</c:forEach>
			</c:if>
			</tbody>
			</table>
			<div class="pagination">${page}</div>
	</form:form>
	</div>
	<div id="changeMoneyDiv" class="hide BoxDiv">
		<form id="changeMoneyForm" action="${ctx}/sys/commonUser/changeCreditLineSave" class="breadcrumb form-search checkForm" >
			<input type="hidden" name="userId" value="${user.id }"> 
			<div class="control-group" >
				<label class="control-label">当前额度：￥<span id="nowCredit"></span>元</label>
			</div>
			<div class="control-group">
				<label class="control-label">调整额度为：<input type="text" name="sum" class="input-medium"/><span>元</span></label>
			</div>
			<div class="control-group">
				<div class="controls">
				<input type="submit" value="确定" class="btn btn-primary">
				<input type="button" value="取消" class="btn btn-primary" onclick="changeMoneyDivClose()">
				</div>
			</div>
		</form>
	</div>
</body>
</html>